--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';

DROP TABLE se_gam_ilot;

CREATE TABLE se_gam_ilot AS (SELECT * FROM &erp.gam_ilot WHERE 1=2);








 INSERT INTO se_gam_ilot

    (SELECT  id section_cod,
             '0' ilot_cod,
             0 enreg_id,
             'N' enreg_s,
             '.' ilot_lib,
             NULL ilot_lib2,
             0 chgtps_typ

        FROM uv_psections s
        ) ;


 UPDATE se_gam_ilot tf SET enreg_id=(select enreg_id FROM &erp.gam_ilot f WHERE f.section_cod=tf.section_cod AND f.ilot_cod=tf.ilot_cod) ;
 UPDATE se_gam_ilot tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;



 CALL uvse_synchroverserp('section_cod@ilot_cod','GAM_ILOT','O') ;

 commit;
 
 
select * from (
SELECT &outils.stragg(source) source, section_cod, ilot_cod, enreg_id, enreg_s, ilot_lib, ilot_lib2, chgtps_typ
FROM (
  SELECT 'uv' source ,g.* FROM se_gam_ilot g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.gam_ilot g

  )
GROUP BY  section_cod, ilot_cod, enreg_id, enreg_s, ilot_lib, ilot_lib2, chgtps_typ
HAVING Count(1)!=2) r
ORDER BY  ilot_cod;